#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define MAX_DIGITS 1030  // 支持1024位大整数

// 大整数结构体：符号(1正,-1负) + 逆序存储的数字数组 + 有效位数
typedef struct {
    int sign;          // 1: 正数, -1: 负数
    int digits[MAX_DIGITS]; // 逆序存储（digits[0]是个位）
    int len;           // 有效位数
} BigInt;

// 初始化大整数
void init_bigint(BigInt *num) {
    num->sign = 1;
    memset(num->digits, 0, sizeof(num->digits));
    num->len = 0;
}

// 从字符串解析大整数
void str_to_bigint(const char *str, BigInt *num) {
    init_bigint(num);
    int start = 0;
    if (str[0] == '-') {
        num->sign = -1;
        start = 1;
    }
    int str_len = strlen(str);
    num->len = str_len - start;
    // 逆序存储（个位放在digits[0]）
    for (int i = 0; i < num->len; i++) {
        num->digits[i] = str[str_len - 1 - i] - '0';
    }
    // 去除前导零
    while (num->len > 0 && num->digits[num->len - 1] == 0) {
        num->len--;
    }
    if (num->len == 0) {
        num->sign = 1; // 零的符号为正
    }
}

// 比较两个大整数的绝对值（a > b返回1，a == b返回0，a < b返回-1）
int compare_abs(const BigInt *a, const BigInt *b) {
    if (a->len > b->len) return 1;
    if (a->len < b->len) return -1;
    for (int i = a->len - 1; i >= 0; i--) {
        if (a->digits[i] > b->digits[i]) return 1;
        if (a->digits[i] < b->digits[i]) return -1;
    }
    return 0;
}

// 大整数加法（仅处理绝对值相加，不考虑符号）
void add_abs(const BigInt *a, const BigInt *b, BigInt *result) {
    init_bigint(result);
    int carry = 0;
    int max_len = (a->len > b->len) ? a->len : b->len;
    for (int i = 0; i < max_len; i++) {
        int sum = a->digits[i] + b->digits[i] + carry;
        result->digits[i] = sum % 10;
        carry = sum / 10;
    }
    if (carry > 0) {
        result->digits[max_len] = carry;
        result->len = max_len + 1;
    } else {
        result->len = max_len;
    }
}

// 大整数减法（仅处理a_abs >= b_abs，返回a_abs - b_abs）
void subtract_abs(const BigInt *a, const BigInt *b, BigInt *result) {
    init_bigint(result);
    int borrow = 0;
    for (int i = 0; i < a->len; i++) {
        int diff = a->digits[i] - b->digits[i] - borrow;
        if (diff < 0) {
            diff += 10;
            borrow = 1;
        } else {
            borrow = 0;
        }
        result->digits[i] = diff;
    }
    // 计算有效长度（去除前导零）
    result->len = a->len;
    while (result->len > 0 && result->digits[result->len - 1] == 0) {
        result->len--;
    }
    if (result->len == 0) {
        result->len = 1; // 确保至少有一位（零）
    }
}

// 大整数加法（带符号）
void add_bigint(const BigInt *a, const BigInt *b, BigInt *result) {
    if (a->sign == b->sign) {
        // 符号相同：绝对值相加，符号不变
        add_abs(a, b, result);
        result->sign = a->sign;
    } else {
        // 符号不同：绝对值相减，符号取绝对值大的数
        int cmp = compare_abs(a, b);
        if (cmp == 1) {
            subtract_abs(a, b, result);
            result->sign = a->sign;
        } else if (cmp == -1) {
            subtract_abs(b, a, result);
            result->sign = b->sign;
        } else {
            // 绝对值相等，结果为零
            init_bigint(result);
            result->len = 1;
            result->digits[0] = 0;
        }
    }
}

// 大整数减法（result = a - b）
void subtract_bigint(const BigInt *a, const BigInt *b, BigInt *result) {
    BigInt b_neg;
    init_bigint(&b_neg);
    memcpy(&b_neg, b, sizeof(BigInt));
    b_neg.sign *= -1; // 转为-b
    add_bigint(a, &b_neg, result);
}

// 大整数乘法（仅处理绝对值相乘）
void multiply_abs(const BigInt *a, const BigInt *b, BigInt *result) {
    init_bigint(result);
    for (int i = 0; i < a->len; i++) {
        int carry = 0;
        for (int j = 0; j < b->len; j++) {
            int product = a->digits[i] * b->digits[j] + result->digits[i + j] + carry;
            result->digits[i + j] = product % 10;
            carry = product / 10;
        }
        if (carry > 0) {
            result->digits[i + b->len] += carry;
        }
    }
    // 计算有效长度
    result->len = a->len + b->len;
    while (result->len > 0 && result->digits[result->len - 1] == 0) {
        result->len--;
    }
    if (result->len == 0) {
        result->len = 1;
    }
}

// 大整数乘法（带符号）
void multiply_bigint(const BigInt *a, const BigInt *b, BigInt *result) {
    multiply_abs(a, b, result);
    result->sign = a->sign * b->sign; // 符号为两者乘积
}

// 大整数除以单精度整数（用于辅助除法）
void divide_by_digit(const BigInt *a, int digit, BigInt *quotient, int *remainder) {
    init_bigint(quotient);
    *remainder = 0;
    for (int i = a->len - 1; i >= 0; i--) {
        int current = *remainder * 10 + a->digits[i];
        quotient->digits[i] = current / digit;
        *remainder = current % digit;
    }
    // 计算商的长度
    quotient->len = a->len;
    while (quotient->len > 0 && quotient->digits[quotient->len - 1] == 0) {
        quotient->len--;
    }
    if (quotient->len == 0) {
        quotient->len = 1;
    }
    quotient->sign = a->sign;
}

// 大整数左移（乘以10^shift）
void left_shift(BigInt *num, int shift) {
    if (num->len == 1 && num->digits[0] == 0) return; // 零不移动
    for (int i = num->len - 1; i >= 0; i--) {
        num->digits[i + shift] = num->digits[i];
    }
    memset(num->digits, 0, shift * sizeof(int)); // 低位补零
    num->len += shift;
}

// 大整数除法和取模（a = b * quotient + remainder，0 <= |remainder| < |b|）
void divide_bigint(const BigInt *a, const BigInt *b, BigInt *quotient, BigInt *remainder) {
    init_bigint(quotient);
    init_bigint(remainder);

    // 处理除数为零的情况（题目保证输入合法，此处简化）
    if (b->len == 1 && b->digits[0] == 0) {
        fprintf(stderr, "除数不能为零\n");
        exit(1);
    }

    BigInt a_abs, b_abs;
    init_bigint(&a_abs);
    init_bigint(&b_abs);
    memcpy(&a_abs, a, sizeof(BigInt));
    memcpy(&b_abs, b, sizeof(BigInt));
    a_abs.sign = 1;
    b_abs.sign = 1;

    if (compare_abs(&a_abs, &b_abs) < 0) {
        // 被除数小于除数，商为0，余数为被除数
        remainder->sign = a->sign;
        memcpy(remainder->digits, a->digits, a->len * sizeof(int));
        remainder->len = a->len;
        return;
    }

    // 初始化余数为0
    BigInt temp, current;
    init_bigint(&temp);
    init_bigint(&current);

    for (int i = a_abs.len - 1; i >= 0; i--) {
        // 余数左移一位，加上当前数字
        left_shift(&temp, 1);
        temp.digits[0] = a_abs.digits[i];
        // 修正长度
        if (temp.len == 0 || (temp.len > 1 && temp.digits[temp.len - 1] == 0)) {
            temp.len = 1;
            while (temp.len > 0 && temp.digits[temp.len - 1] == 0) temp.len--;
            if (temp.len == 0) temp.len = 1;
        }

        // 计算当前位的商（0-9）
        int q = 0;
        while (compare_abs(&temp, &b_abs) >= 0) {
            subtract_abs(&temp, &b_abs, &current);
            memcpy(&temp, &current, sizeof(BigInt));
            q++;
        }

        // 商左移一位，加上当前位
        left_shift(quotient, 1);
        quotient->digits[0] = q;
        if (quotient->len == 0 || (quotient->len > 1 && quotient->digits[quotient->len - 1] == 0)) {
            quotient->len = 1;
            while (quotient->len > 0 && quotient->digits[quotient->len - 1] == 0) quotient->len--;
            if (quotient->len == 0) quotient->len = 1;
        }
    }

    // 设置余数和商的符号
    remainder->sign = a->sign;
    memcpy(remainder->digits, temp.digits, temp.len * sizeof(int));
    remainder->len = temp.len;
    quotient->sign = a->sign * b->sign;

    // 清理临时变量
    init_bigint(&a_abs);
    init_bigint(&b_abs);
    init_bigint(&temp);
    init_bigint(&current);
}

// 复制大整数
void copy_bigint(const BigInt *src, BigInt *dest) {
    dest->sign = src->sign;
    dest->len = src->len;
    memcpy(dest->digits, src->digits, MAX_DIGITS * sizeof(int));
}

// 扩展欧几里得算法（迭代版）
void extended_gcd(BigInt *gcd, BigInt *x, BigInt *y, const BigInt *a, const BigInt *b) {
    BigInt old_r, r, old_s, s, old_t, t;
    BigInt quotient, temp;

    // 初始化变量：old_r = a, r = b
    copy_bigint(a, &old_r);
    copy_bigint(b, &r);

    // 初始化系数：old_s=1, s=0; old_t=0, t=1
    init_bigint(&old_s);
    old_s.len = 1;
    old_s.digits[0] = 1;
    old_s.sign = 1;

    init_bigint(&s);
    s.len = 1;
    s.digits[0] = 0;
    s.sign = 1;

    init_bigint(&old_t);
    old_t.len = 1;
    old_t.digits[0] = 0;
    old_t.sign = 1;

    init_bigint(&t);
    t.len = 1;
    t.digits[0] = 1;
    t.sign = 1;

    // 迭代计算，直到r为0
    while (!(r.len == 1 && r.digits[0] == 0)) {
        // 计算商：quotient = old_r / r
        divide_bigint(&old_r, &r, &quotient, &temp);

        // 更新余数：old_r, r = r, old_r - quotient*r
        BigInt temp_r;
        copy_bigint(&r, &temp_r);
        multiply_bigint(&quotient, &r, &temp);
        subtract_bigint(&old_r, &temp, &r);
        copy_bigint(&temp_r, &old_r);

        // 更新系数s：old_s, s = s, old_s - quotient*s
        BigInt temp_s;
        copy_bigint(&s, &temp_s);
        multiply_bigint(&quotient, &s, &temp);
        subtract_bigint(&old_s, &temp, &s);
        copy_bigint(&temp_s, &old_s);

        // 更新系数t：old_t, t = t, old_t - quotient*t
        BigInt temp_t;
        copy_bigint(&t, &temp_t);
        multiply_bigint(&quotient, &t, &temp);
        subtract_bigint(&old_t, &temp, &t);
        copy_bigint(&temp_t, &old_t);
    }

    // 结果赋值
    copy_bigint(&old_r, gcd);
    copy_bigint(&old_s, x);
    copy_bigint(&old_t, y);

    // 清理临时变量
    init_bigint(&old_r);
    init_bigint(&r);
    init_bigint(&old_s);
    init_bigint(&s);
    init_bigint(&old_t);
    init_bigint(&t);
    init_bigint(&quotient);
    init_bigint(&temp);
}

// 打印大整数
void print_bigint(const BigInt *num) {
    if (num->len == 1 && num->digits[0] == 0) {
        printf("0");
        return;
    }
    if (num->sign == -1) {
        printf("-");
    }
    // 从最高位打印（逆序数组的最后一个有效位）
    for (int i = num->len - 1; i >= 0; i--) {
        printf("%d", num->digits[i]);
    }
}

int main() {
    char a_str[1025], b_str[1025];
    scanf("%s %s", a_str, b_str);

    BigInt a, b, gcd, x, y;
    str_to_bigint(a_str, &a);
    str_to_bigint(b_str, &b);

    extended_gcd(&gcd, &x, &y, &a, &b);

    print_bigint(&gcd);
    printf(" ");
    print_bigint(&x);
    printf(" ");
    print_bigint(&y);
    printf("\n");

    return 0;
}